package com.qcby.demo.proxyaop.reflect;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * @className: Hello
 * @description:
 * @author: lxt
 * @create: 2021-05-13 16:05
 **/
@Slf4j
@Controller("hello")
public class Hello {

    public void say(){
      System.out.println("入参：");
      log.info("hello world!");
      System.out.println("出参：");
    }

    @RequestMapping(value = "say",method = {RequestMethod.DELETE,RequestMethod.POST})
    public String say(String name){
        System.out.println("入参：name=>"+name);
        log.info("hello world:{}",name);
        System.out.println("出参：name=>"+name);
        return name;
    }
    public static String say(String name,String number){
        System.out.println("入参：name=>"+name+";number=>"+number);
        log.info("hello world:{}#{}",name,number);
        String result  = "name=>"+name+";;number=>"+number;
        System.out.println("出参："+result);
        return result;
    }

    /**
     *  static : 下去回顾一下，博客复习。
     *
     *
     * @param args
     */
    /**
     *
     *  spring aop
     * @Controller
     *  Spring Mvc  Controller  method  => 反射
     *
     *  url =>  controller -》 method
     *
     * @param args
     */
    public static void main(String[] args) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
//        Hello hello = new Hello();
//        hello.say();
//        hello.say("小麦！");
        Hello.say("小麦！","001");

        Class clz = Hello.class;
        Controller controller = (Controller) clz.getAnnotation(Controller.class);
        System.out.println(controller);

        // 获取无参数
        Method say = clz.getMethod("say");
        say.invoke(new Hello());

        Method say1 = clz.getMethod("say",String.class);
        say1.invoke(new Hello(),"小麦！");


        RequestMapping requestMapping = say1.getAnnotation(RequestMapping.class);
        System.out.println(requestMapping);





    }
}
